package com.golddaymicromall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.golddaymicromall.activity.R;
import com.golddaymicromall.bean.ProductInfo;
import com.golddaymicromall.img.ImageLoad;
import com.golddaymicromall.model.HttpModel;

import java.util.List;

/**
 * Created by dawd on 2016/3/11.
 */
public class OrderDetailAdapter extends BaseAdapter {
    private List<ProductInfo> list;
    private Context ctx;
    private ImageLoad load;
    private int selectID;
    LayoutInflater layoutinflater;
    public OrderDetailAdapter(List<ProductInfo> list, Context ctx) {
        this.list = list;
        this.ctx = ctx;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    // 自定义的选中方法
    public void setSelectID(int position) {
        selectID = position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder hold;
        View view = convertView;
        if (view == null) {
            hold = new ViewHolder();
            layoutinflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            view = layoutinflater.inflate(R.layout.item_orderdetail, null);
            hold.orderDetail_productImg = (ImageView) view.findViewById(R.id.orderDetail_productImg);
            hold.orderDetail_productPrice = (TextView) view.findViewById(R.id.orderDetail_productPrice);
            hold.orderDetail_productTitle = (TextView) view.findViewById(R.id.orderDetail_productTitle);
            hold.orderDetail_productCount = (TextView) view.findViewById(R.id.orderDetail_productCount);
            view.setTag(hold);

        } else {
            hold = (ViewHolder) view.getTag();

        }
        Glide.with(ctx)
                .load(new HttpModel().IMGURL+list.get(position).getImage())
                .into(hold.orderDetail_productImg);
        hold.orderDetail_productPrice.setText("￥" + list.get(position).getPrice());
        hold.orderDetail_productTitle.setText(list.get(position).getProductname());
        hold.orderDetail_productCount.setText(list.get(position).getCon());
        return view;
    }



    public static class ViewHolder {
        ImageView orderDetail_productImg;
        TextView orderDetail_productTitle;
        TextView orderDetail_productPrice;
        TextView orderDetail_productCount;

    }
}
